package com.youlu.campus.service.activity.impl;

import com.alibaba.fastjson.JSON;
import com.mongodb.client.result.UpdateResult;
import com.youlu.campus.activity.service.ActivityLotteryConfigService;
import com.youlu.campus.base.exception.BusinessException;
import com.youlu.campus.entity.ActivityTaskInfo;
import com.youlu.campus.entity.ActivityTaskRule;
import com.youlu.campus.entity.VO.req.ActivityCopyReq;
import com.youlu.campus.entity.VO.req.ActivityTaskQueryVO;
import com.youlu.campus.entity.VO.req.CopyTaskRuleReq;
import com.youlu.campus.entity.domain.PlayBillDomain;
import com.youlu.campus.entity.enums.TaskBizType;
import com.youlu.campus.service.activity.ActivityRewardRuleService;
import com.youlu.campus.service.activity.ActivityTaskRuleService;
import com.youlu.campus.service.activity.ActivityTaskService;
import lombok.extern.slf4j.Slf4j;
import ma.glasnost.orika.MapperFacade;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.bson.types.ObjectId;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.repository.support.PageableExecutionUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

@Slf4j
@Service
public class ActivityTaskServiceImpl implements ActivityTaskService {
    @Autowired
    private MongoTemplate mongoTemplate;
    @Autowired
    private ActivityTaskRuleService activityTaskRuleService;
    @Autowired
    private RedisTemplate<String, String> redisTemplate;
    private String TASK_KEY = "com.luyou.task.:%s::%s";

    @Autowired
    private MapperFacade mapperFacade;
    
    @Lazy
    @Autowired
    private ActivityRewardRuleService activityRewardRuleService;

    @Autowired
    private ActivityLotteryConfigService activityLotteryConfigService;

    @Override
    public Page<ActivityTaskInfo> list(ActivityTaskQueryVO req) {
        log.info(":>>> 开始获取活动任务列表:{}", JSON.toJSON(req));
        if (Objects.isNull(req) || StringUtils.isBlank(req.getActivityId())) {
            log.error(":>>> 活动任务参数错误:活动ID不能为空");
            throw new BusinessException("活动ID不能为空");
        }
        Query query = new Query().addCriteria(Criteria.where("activityId").is(req.getActivityId()));
        if (Objects.nonNull(req.getTaskBizType())) {
            query.addCriteria(Criteria.where("taskBizType").is(req.getTaskBizType()));
        }
        query.addCriteria(Criteria.where("deleted").ne(true));
        long count = mongoTemplate.count(query, ActivityTaskInfo.class);
        PageRequest pageRequest = PageRequest.of(req.getPage() - 1, req.getPageSize());
//        query.with(new Sort(Sort.Direction.DESC, "createdTime"));
        Sort sort = Sort.by(Sort.Direction.DESC, "createdTime");
        query.with(sort);
        List<ActivityTaskInfo> datas = mongoTemplate.find(query.with(pageRequest), ActivityTaskInfo.class);
        return PageableExecutionUtils.getPage(datas, pageRequest, () -> count);
    }

    @Override
    public boolean create(ActivityTaskInfo req) {
//        if (Objects.isNull(req) || Objects.isNull(req.getTaskBizType()) || StringUtils.isBlank(req.getActivityId()) || Objects.isNull(req.getHasShare()) ||
//                StringUtils.isBlank(req.getName()) || StringUtils.isBlank(req.getDetail()) || Objects.isNull(req.getShowDetail()) || StringUtils.isBlank(req.getUnit()) ||
//                StringUtils.isBlank(req.getH5Tips()) || StringUtils.isBlank(req.getBackGroundImageUrl()) || Objects.isNull(req.getRatio()) || StringUtils.isBlank(req.getBizType())) {
//            log.error(":>>> 创建任务参数错误:活动ID、是否分享、任务类型为空");
//            throw new BusinessException(">>> 创建任务参数错误:活动ID、是否分享、任务类型为空");
//        }
        /*
        ActivityTaskInfo exist = this.find(req.getActivityId(), req.getTaskBizType());
        if (Objects.nonNull(exist)) {
            log.error(":>>> 活动:{},任务:{} 已经存在", req.getActivityId(), req.getTaskBizType());
            throw new BusinessException("活动任务已经存在");
        }
        if (Boolean.TRUE.equals(req.getHasShare())) {
            if (Objects.isNull(req.getPlayBill()) || StringUtils.isNotBlank(req.getPlayBill().getPlayBillImageUrl()) || StringUtils.isNotBlank(req.getPlayBill().getPlayBillImageUrlQQH5()) ||
                    Objects.isNull(req.getProps()) || req.getProps().length == 0) {
                log.error(":>>> 分享任务海报信息为空:微信海报或QQ海报为空");
                throw new BusinessException("分享任务海报信息为空:微信海报或QQ海报为空");
            }
        }
        */
        req.setCreatedTime(new Date());
        req.setId(null);
        mongoTemplate.insert(req);
        switch (req.getTaskBizType()) {
            case INVITE:
                if (Objects.isNull(req.getRangNum()) || Objects.isNull(req.getProps()) || req.getProps().length == 0) {
                    log.error(":>>> 分享任务参数错误:排行榜数量或海报元素为空");
                }
                break;
            case ORGANIZER:
                if (Objects.isNull(req.getRangNum()) || Objects.isNull(req.getProps()) || req.getProps().length == 0) {
                    log.error(":>>> 分享任务参数错误:排行榜数量或海报元素为空");
                }
                break;
            case LEARNING:
            case OFF_LINE:
            case WELFARE:
            case BROADCASAT:
            case QA:
            case PRAXIS:
            case WORK_COLLECTION:
            case KNOWLEDGE_CHALLENGE:
            case FOLLOW_WECHAT:
            case SHARE_FRIENDS:
            case SHARE_WEIBO:
            case SHARE_XIAOHONGSHU:
            case SHARE_DOUYIN:
            case SHARE_VIDEO_PLAYBILL:
            case SHARE_VIDEO:
                addRule(req);
                break;
            default:
                break;
        }
        return true;
    }

    public void addRule(ActivityTaskInfo req) {
        ActivityTaskRule rule = new ActivityTaskRule();
        rule.setActivityId(req.getActivityId());
        rule.setBizType(req.getTaskBizType().name());
        rule.setCreatedTime(new Date());
        rule.setTaskId(req.getId());
        rule.setDefaulted(req.getDefaulted());
        rule.setPoints(req.getPoints());
        rule.setLogo(req.getLogo());
        rule.setThreshold(req.getThreshold());
        rule.setUnit(req.getUnit());
        mongoTemplate.insert(rule);
    }

    @Override
    public boolean update(ActivityTaskInfo req) {
        log.info(":>>> 开始更新活动任务:{}", JSON.toJSONString(req));
        if (Objects.isNull(req) || StringUtils.isBlank(req.getId())) {
            log.error(":>>> 修改任务信息错误:id为空");
            throw new BusinessException("修改任务参数错误");
        }
        ActivityTaskInfo taskInfo = this.findOne(req.getId());
        if (Objects.isNull(taskInfo)) {
            log.error(":>>> 任务不存在:{}", req.getId());
            throw new BusinessException("任务不存在");
        }
        Query query = new Query().addCriteria(Criteria.where("id").is(req.getId()));
        Update update = new Update();
        if (!StringUtils.isBlank(req.getName())) {
            update.set("name", req.getName());
        }
        if (Objects.nonNull(req.getStatus())) {
            update.set("status", req.getStatus());
        }
        if (Objects.nonNull(req.getShowDetail())) {
            update.set("showDetail", req.getShowDetail());
        }
        if (Objects.nonNull(req.getDetail())) {
            update.set("detail", req.getDetail());
        }
        if (!CollectionUtils.isEmpty(req.getImageUrls())) {
            update.set("imageUrls", req.getImageUrls());
        }
        if (StringUtils.isNotBlank(req.getUnit())) {
            update.set("unit", req.getUnit());
        }
        if (StringUtils.isNotBlank(req.getRankingListContent())) {
            update.set("rankingListImageUrl", req.getRankingListContent());
        }
        if (StringUtils.isNotBlank(req.getRankingListContent())) {
            update.set("rankingListContent", req.getRankingListContent());
        }
        if (StringUtils.isNotBlank(req.getRewardDesc())) {
            update.set("rewardDesc", req.getRewardDesc());
        }
        if (StringUtils.isNotBlank(req.getRewardImageUrl())) {
            update.set("rewardImageUrl", req.getRewardImageUrl());
        }
        if (StringUtils.isNotBlank(req.getTips())) {
            update.set("tips", req.getTips());
        }
        if (Objects.nonNull(req.getUpdateRanking())) {
            update.set("updateRanking", req.getUpdateRanking());
        }
        if (StringUtils.isNotBlank(req.getH5Tips())) {
            update.set("h5Tips", req.getH5Tips());
        }
        update.set("signInDay", req.getSignInDay());
        if (StringUtils.isNotBlank(req.getSignInTipImgUrl())) {
            update.set("signInTipImgUrl", req.getSignInTipImgUrl());
        }
        update.set("outerLinkerImage", req.getOuterLinkerImage());
        update.set("priority", req.getPriority());
        update.set("backGroundImageUrl", req.getBackGroundImageUrl());
        update.set("shareInviteButtonType", req.getShareInviteButtonType());
        update.set("shareInviteButtonBackGroundImgUrl", req.getShareInviteButtonBackGroundImgUrl());

        if (Objects.nonNull(req.getHasBackGroundImageUrl())) {
            update.set("hasBackGroundImageUrl", req.getHasBackGroundImageUrl());
        }
        if (Objects.nonNull(req.getRangNum())) {
            update.set("rangNum", req.getRangNum());
        }
        if (Objects.nonNull(req.getHasShare())) {
            update.set("hasShare", req.getHasShare());
        }
        if (Objects.nonNull(req.getProps())) {
            update.set("props", req.getProps());
        }
        if (StringUtils.isNotBlank(req.getHeaderTips())) {
            update.set("headerTips", req.getHeaderTips());
        }
        if (StringUtils.isNotBlank(req.getHeaderSubTips())) {
            update.set("headerSubTips", req.getHeaderSubTips());
        }
        if (Objects.nonNull(req.getLayoutNo())) {
            update.set("layoutNo", req.getLayoutNo());
        }
        if (StringUtils.isNotBlank(req.getRule())) {
            update.set("rule", req.getRule());
        }
        if (StringUtils.isNotBlank(req.getLinkerUrl())) {
            update.set("linkerUrl", req.getLinkerUrl());
        }
        if (Objects.nonNull(req.getShowRuleAndLiner())) {
            update.set("showRuleAndLiner", req.getShowRuleAndLiner());
        }
        if (Objects.nonNull(req.getThreshold())) {
            update.set("threshold", req.getThreshold());
        }
        if (Objects.nonNull(req.getPoints())) {
            update.set("points", req.getPoints());
        }
        if (Objects.nonNull(req.getExtraPoints())) {
            update.set("extraPoints", req.getExtraPoints());
        }
        if (Objects.nonNull(req.getLogo())) {
            update.set("logo", req.getLogo());
        }
        if (Objects.nonNull(req.getRatio())) {
            update.set("ratio", req.getRatio());
        }
        if (Objects.nonNull(req.getDigitCaDetail())) {
            update.set("digitCaDetail", req.getDigitCaDetail());
        }
        if (Objects.nonNull(req.getShowDigit())) {
            update.set("showDigit", req.getShowDigit());
        }
        if (StringUtils.isNotBlank(req.getDefaultTips())) {
            update.set("defaultTips", req.getDefaultTips());
        }
        if (StringUtils.isNotBlank(req.getInviteButtonTips())) {
            update.set("inviteButtonTips", req.getInviteButtonTips());
        }
        if (StringUtils.isNotBlank(req.getProgressBarType())) {
            update.set("progressBarType", req.getProgressBarType());
        }
        if (StringUtils.isNotBlank(req.getTitle())) {
            update.set("title", req.getTitle());
        }
        if (StringUtils.isNotBlank(req.getSubTitle())) {
            update.set("subTitle", req.getSubTitle());
        }
        if (Objects.nonNull(req.getFileTypes()) && req.getFileTypes().size() != 0) {
            update.set("fileTypes", req.getFileTypes());
        }
        if (StringUtils.isNotBlank(req.getButtonName())) {
            update.set("buttonName", req.getButtonName());
        }
        update.set("inviteBackGroundImageUrl", req.getInviteBackGroundImageUrl());
        if (Objects.nonNull(req.getHasInviteLimit())) {
            update.set("hasInviteLimit", req.getHasInviteLimit());
        }
        if (Objects.nonNull(req.getInviteLimit())) {
            update.set("inviteLimit", req.getInviteLimit());
        }
        if (Objects.nonNull(req.getInviteLimitQuantity())) {
            update.set("inviteLimitQuantity", req.getInviteLimitQuantity());
        }
        if (StringUtils.isNotBlank(req.getInviteLimitTips())) {
            update.set("inviteLimitTips", req.getInviteLimitTips());
        }
        if (StringUtils.isNotBlank(req.getSubTips())) {
            update.set("subTips", req.getSubTips());
        }
        if (StringUtils.isNotBlank(req.getCaDisplay())) {
            update.set("caDisplay", req.getCaDisplay());
        }
        if (StringUtils.isNotBlank(req.getQuantityDisplay())) {
            update.set("quantityDisplay", req.getQuantityDisplay());
        }
        if (StringUtils.isNotBlank(req.getOuterLinker())) {
            update.set("outerLinker", req.getOuterLinker());
        }
        if (StringUtils.isNotBlank(req.getCanBackGroundImage())) {
            update.set("canBackGroundImage", req.getCanBackGroundImage());
        }
        if (StringUtils.isNotBlank(req.getNotCanBackGroundImage())) {
            update.set("notCanBackGroundImage", req.getNotCanBackGroundImage());
        }
        if (Objects.nonNull(req.getOpened())) {
            update.set("opened", req.getOpened());
        }
        if (Objects.nonNull(req.getAvailableThreshold())) {
            update.set("availableThreshold", req.getAvailableThreshold());
        }
        if (Objects.nonNull(req.getTaskAlias())) {
            update.set("taskAlias", req.getTaskAlias());
        }
        if (Objects.nonNull(req.getTaskPendAuditImgUrl())) {
            update.set("taskPendAuditImgUrl", req.getTaskPendAuditImgUrl());
        }
        if (Objects.nonNull(req.getTaskPassAuditImgUrl())) {
            update.set("taskPassAuditImgUrl", req.getTaskPassAuditImgUrl());
        }
        if (Objects.nonNull(req.getPropagandaDesc())) {
            update.set("propagandaDesc", req.getPropagandaDesc());
        }
        if (Objects.nonNull(req.getTaskExtra())) {
            update.set("taskExtra", req.getTaskExtra());
        }
        if (Objects.nonNull(req.getButtonBackgroundColor())) {
            update.set("buttonBackgroundColor", req.getButtonBackgroundColor());
        }
        if (Objects.nonNull(req.getButtonTextColor())) {
            update.set("buttonTextColor", req.getButtonTextColor());
        }
        PlayBillDomain playBill = req.getPlayBill();
        if (Objects.nonNull(playBill)) {
            PlayBillDomain playBillDomain = taskInfo.getPlayBill();
            if (Objects.isNull(playBillDomain)) {
                playBillDomain = new PlayBillDomain();
            }
            if (StringUtils.isNotBlank(playBill.getPlayBillImageUrl())) {
                playBillDomain.setPlayBillImageUrl(playBill.getPlayBillImageUrl());
            }

            if (ArrayUtils.isEmpty(playBill.getPlayBillImageUrls())) {
                playBillDomain.setPlayBillImageUrls(playBill.getPlayBillImageUrls());
            }
            if (StringUtils.isNotBlank(playBill.getPlayBillImageUrlQQH5())) {
                playBillDomain.setPlayBillImageUrlQQH5(req.getPlayBill().getPlayBillImageUrlQQH5());
            }
            if (StringUtils.isNotBlank(playBill.getFontColor())) {
                playBillDomain.setFontColor(playBill.getFontColor());
            }
            if (Objects.nonNull(playBill.getLengthBarcode())) {
                playBillDomain.setLengthBarcode(playBill.getLengthBarcode());
            }
            if (Objects.nonNull(playBill.getWidthBarcode())) {
                playBillDomain.setWidthBarcode(playBill.getWidthBarcode());
            }
            if (StringUtils.isNotBlank(playBill.getShareRecommendedContent())) {
                playBillDomain.setShareRecommendedContent(playBill.getShareRecommendedContent());
            }
            //对象拷贝忽略空值
            BeanUtils.copyProperties(playBill, playBillDomain, getNullPropertyNames(playBill));
            update.set("playBill", playBillDomain);
        }
        if (Objects.nonNull(req.getTaskExecuteType())) {
            update.set("taskExecuteType", req.getTaskExecuteType());
        }
        if (Objects.nonNull(req.getApproveType())) {
            update.set("approveType", req.getApproveType());
        }
        if (Objects.nonNull(req.getTaskApproveTime())) {
            update.set("taskApproveTime", req.getTaskApproveTime());
        }
        if (Objects.nonNull(req.getSendSms())) {
            update.set("sendSms", req.getSendSms());
        }
        if (Objects.nonNull(req.getApprovePassSmsTemplateId())) {
            update.set("approvePassSmsTemplateId", req.getApprovePassSmsTemplateId());
        }
        if (Objects.nonNull(req.getApproveNotPassSmsTemplateId())) {
            update.set("approveNotPassSmsTemplateId", req.getApproveNotPassSmsTemplateId());
        }
        if (StringUtils.isNotBlank(req.getCaGroupName())) {
            update.set("caGroupName", req.getCaGroupName());
        }
        UpdateResult updateResult = mongoTemplate.updateFirst(query, update, ActivityTaskInfo.class);
        ActivityTaskRule rule = activityTaskRuleService.find(taskInfo.getId());
        if (Objects.isNull(rule)) {
            rule = new ActivityTaskRule();
            rule.setActivityId(taskInfo.getActivityId());
            rule.setTaskId(taskInfo.getId());
            rule.setBizType(taskInfo.getTaskBizType().name());
            rule.setUnit(req.getUnit());
            rule.setThreshold(req.getThreshold());
            rule.setPoints(req.getPoints());
            rule.setExtraPoints(req.getPoints());
            rule.setLogo(req.getLogo());
            rule.setDefaulted(req.getDefaulted());
            activityTaskRuleService.create(rule);
        } else {
            Update updateRule = new Update();
            if (StringUtils.isNotBlank(req.getUnit())) {
                updateRule.set("unit", req.getUnit());
            }
            if (Objects.nonNull(req.getThreshold())) {
                updateRule.set("threshold", req.getThreshold());
            }
            if (Objects.nonNull(req.getPoints())) {
                updateRule.set("points", req.getPoints());
            }
            if (Objects.nonNull(req.getExtraPoints())) {
                updateRule.set("extraPoints", req.getExtraPoints());
            }
            if (Objects.nonNull(req.getLogo())) {
                updateRule.set("logo", req.getLogo());
            }
            if (Objects.nonNull(req.getDefaulted())) {
                updateRule.set("defaulted", req.getDefaulted());
            }
            updateRule.set("updatedTime", new Date());
            mongoTemplate.updateFirst(new Query().addCriteria(Criteria.where("id").is(rule.getId())), updateRule,
                    ActivityTaskRule.class);
        }
        //更新抽奖配置中的 邀请贡献值
        if (TaskBizType.INVITE.equals(taskInfo.getTaskBizType())) {
            activityLotteryConfigService.updateInvitePoints(taskInfo.getActivityId());
        }
        return updateResult.getModifiedCount() > 0 ? true : false;
    }

    @Override
    public boolean delete(String taskId) {
        Query query = new Query().addCriteria(Criteria.where("id").is(taskId));
        Update update = new Update();
        update.set("deleted", true);
        UpdateResult updateResult = mongoTemplate.updateFirst(query, update, ActivityTaskInfo.class);
        return updateResult.getModifiedCount() > 0 ? true : false;
    }

    @Override
    public ActivityTaskInfo find(String activityId, TaskBizType taskBizType) {
        log.info(":>>> 开始获取活动任务:{},{}", activityId, taskBizType);
//        String key = String.format(TASK_KEY, activityId, taskBizType.name());
//        String o = (String) redisTemplate.opsForValue().get(key);
//        if (Objects.nonNull(o)) {
//            return JSON.parseObject(o, ActivityTaskInfo.class);
//        }
        Query query =
                new Query().addCriteria(Criteria.where("activityId").is(activityId).and("taskBizType").is(taskBizType));
        ActivityTaskInfo taskInfo = mongoTemplate.findOne(query, ActivityTaskInfo.class);
//        if (Objects.nonNull(taskInfo)) {
//            redisTemplate.opsForValue().set(key, taskInfo, 1, TimeUnit.HOURS);
//        }
        return taskInfo;
    }

    @Override
    public ActivityTaskInfo findById(String activityId, String taskId) {
        Query query = new Query().addCriteria(Criteria.where("id").is(taskId).and("activityId").is(activityId));
        ActivityTaskInfo taskInfo = mongoTemplate.findOne(query, ActivityTaskInfo.class);
        return taskInfo;
    }

    @Override
    public ActivityTaskInfo findOne(String id) {
        Query query = new Query().addCriteria(Criteria.where("id").is(id));
        ActivityTaskInfo taskInfo = mongoTemplate.findOne(query, ActivityTaskInfo.class);
        if (Objects.nonNull(taskInfo)) {
            ActivityTaskRule rule = activityTaskRuleService.find(taskInfo.getId());
            if (rule != null) {
                taskInfo.setThreshold(rule.getThreshold());
                taskInfo.setPoints(rule.getPoints());
            } else {
                rule = activityTaskRuleService.find(taskInfo.getActivityId(), taskInfo.getTaskBizType().name());
                if (Objects.nonNull(rule)) {
                    taskInfo.setThreshold(rule.getThreshold());
                    taskInfo.setPoints(rule.getPoints());
                }
            }
        }
        log.info(":>>> 活动任务基本信息为:{},--{}", id
                , JSON.toJSON(taskInfo));
        return taskInfo;
    }

    @Async
    @Override
    public void doCopyTask(ActivityCopyReq activityCopyReq) {
        String copyActivityId = activityCopyReq.getCopyActivityId();
        String targetCopyActivityId = activityCopyReq.getTargetCopyActivityId();
        String targetCopyActivityName = activityCopyReq.getTargetCopyActivityName();
        log.info("【copy 活动】开始复制活动任务 ->{}", copyActivityId);
        Query query = new Query();
        query.addCriteria(Criteria.where("activityId").is(copyActivityId));
        List<ActivityTaskInfo> taskInfoList = this.mongoTemplate.find(query, ActivityTaskInfo.class);
        if (org.apache.commons.collections4.CollectionUtils.isEmpty(taskInfoList)) {
            log.error("【copy 活动】未找到复制活动任务 ->{}", copyActivityId);
            return;
        }
        Date now = new Date();
        taskInfoList.stream().forEach(activityTaskInfo -> {
            ActivityTaskInfo newActivityTaskInfo = this.mapperFacade.map(activityTaskInfo, ActivityTaskInfo.class);
            String targetTaskId = ObjectId.get().toString();
            newActivityTaskInfo.setId(targetTaskId);
            newActivityTaskInfo.setActivityId(targetCopyActivityId);
            newActivityTaskInfo.setCreatedTime(now);
            newActivityTaskInfo.setUpdatedTime(now);
            this.mongoTemplate.save(newActivityTaskInfo);
            CopyTaskRuleReq copyTaskRuleReq = new CopyTaskRuleReq();
            copyTaskRuleReq.setCopyActivityId(copyActivityId);
            copyTaskRuleReq.setTargetCopyTaskId(targetTaskId);
            copyTaskRuleReq.setCopyTaskId(activityTaskInfo.getId());
            copyTaskRuleReq.setBizType(activityTaskInfo.getTaskBizType().name());
            copyTaskRuleReq.setTargetCopyActivityId(targetCopyActivityId);
            activityTaskRuleService.doCopyTaskRule(copyTaskRuleReq);
            switch (activityTaskInfo.getTaskBizType()) {
                case INVITE://分享
                    activityRewardRuleService.doCopyActivityRewardRule(copyTaskRuleReq);
                    break;
                case ORGANIZER://承办单位
                    activityRewardRuleService.doCopyActivityRewardRule(copyTaskRuleReq);
                    break;
            }
        });
        log.info("【copy 活动】结束复制活动任务", copyActivityId);
    }

    public static String[] getNullPropertyNames(Object source) {
        final BeanWrapper src = new BeanWrapperImpl(source);
        java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();

        Set<String> emptyNames = new HashSet<String>();
        for (java.beans.PropertyDescriptor pd : pds) {
            Object srcValue = src.getPropertyValue(pd.getName());
            if (srcValue == null) emptyNames.add(pd.getName());
        }
        String[] result = new String[emptyNames.size()];
        return emptyNames.toArray(result);
    }
}
